<?php
namespace app\admin\service\material;

use app\admin\logic\material\Category as CategoryLogic;
use app\common\service\BaseService;
use think\annotation\Inject;
use think\facade\Request;

class Category extends BaseService
{
    /**
     * @Inject()
     * @var CategoryLogic
     */
    protected $cateLogic;

    /**
     * 创建分组
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-04-21
     * @return   [type]                         [description]
     */
    public function createCategory($type)
    {
        $category                  = Request::post();
        $category['material_type'] = $type;
        $this->cateLogic->createCategory($category);

        return $this->parseToData([], 1, '创建分组成功');

    }

    /**
     * 修改分组
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-04-23
     * @param    [type]                         $id [description]
     * @return   [type]                             [description]
     */
    public function updateCategory($id)
    {
        $title = Request::put('title');

        app(CategoryLogic::class)->updateCategory($id, ['title' => $title]);

        return $this->parseToData([], 1, '修改分组成功');
    }

    /**
     * 删除分组
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-04-23
     * @param    [type]                         $id [description]
     * @return   [type]                             [description]
     */
    public function deleteCategory($id)
    {
        app(CategoryLogic::class)->deleteCategory($id);

        return $this->parseToData([], 1, '删除成功');
    }
}
